package chapter10;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @create 2018-03-22 上午8:56
 */
public class RegularTest {
    private static final Logger LOGGER = LoggerFactory.getLogger(RegularTest.class);

    public static void main(String[] args) {
        String str = "123yootk";
        LOGGER.info(String.valueOf(str.matches("\\d+")));

        str = "hello*()(*)youtk(*&^%$mldn@#$";
        String regex = "[^a-z]";
        LOGGER.info(str.replaceAll(regex, ""));

        str = "yootk9msldy789dsd90sdfd";
        regex = "\\d+";
        String[] strings = str.split(regex);
        for (String s : strings) {
            LOGGER.info(s);
        }

        str = "10.10";
        regex = "\\d+(\\.\\d+)?";
        if (str.matches(regex)) {
            LOGGER.info(String.valueOf(Double.parseDouble(str)));
        }

        regex = "\\d{4}-\\d{2}-\\d{2}";
        str = "1895-01-23";
        if (str.matches(regex)) {
            try {
                Date dt = new SimpleDateFormat("yyyy-MM-dd").parse(str);
                LOGGER.info(dt.toString());
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
    }
}
